package com.jied.duodian.util.handler;

import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Description:
 *
 * @author LiJie
 * @date Created on 2020/10/30
 * WWW https://github.com/j6l
 */
@Component
public class EntryPointUnauthorizedHandler implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        response.setStatus( HttpServletResponse.SC_FORBIDDEN );
        response.setHeader( "Content-Type", "application/json;charset=utf-8" );
        PrintWriter writer = response.getWriter();
        writer.write( "{\"权限\":\"错误\",\"msg\":\"联系管理员解决\"} " );
        writer.flush();
        writer.close();
    }
}
